﻿@using KRM.Core
@using KRM.Core.Library
@model tblCustomer
@{
    ViewBag.Title = "Customer Notes";
    Layout = "~/Views/Shared/_PopupLayout.cshtml";
    var address = Model.tblAddresses.FirstOrDefault() ?? new tblAddress();
    var lstTasks = Model.GetRelatedTasks().OrderByDescending(p => p.TaskID);
    var lstNotes = Model.CustomerNotes.OrderByDescending(p => p.Id);
}
<script>
    $(document).ready(function () {
        LoadDataTable($('#CustomerTasks'));
    });
</script>
<div class="box customer-note">
    <div class="box-title customer-note-title">
        <h4><i class="icon-tasks"></i> Related Tasks/Notes of @address.Title @address.Forename @address.Surname </h4>
    </div>
    <div class="box-content customer-note-content">
        <div class="box box-note">
            <div class="box-title">
                <b>Customer Notes(@lstNotes.Count())</b>
                @*                  <div class="actions">
					<a href="#" class="btn btn-mini content-slideUp"><i class="icon-angle-down"></i></a>
					</div>*@
            </div>
            <div class="box-content">
                <div id="customernote-template" style="display: none">
                    <div  class="row-fluid ticket-comment-row">
                        <div class="span1">
                            <img alt="" src="/Upload/Avatar/@(Users.Current(User.Identity.Name).Avatar ?? "avatar-default.jpg")" onError="this.src='/upload/avatar/avatar-default.jpg';" style="text-align: center; height: 40px; max-width: 40px; background-color: #ddd !important;">
                        </div>
                        <div class="span11">
                            <div class="row-fluid">
                                <strong>@(Users.Current(User.Identity.Name).Username)</strong>
                                <span class="ticket-comment-time">
                                    new note
                                </span>
                            </div>
                            <div class="ticket-comment"style="color: rgb(0, 0, 189);">
                            </div>
                        </div>
                    </div>
                    </div>
                <div class="row-fluid ticket-comment-row">
                    <form id="fr-CommentNote" style="display: none;">
                        <div class="span1">
                            <img alt="" src="/Upload/Avatar/@(Users.Current(User.Identity.Name).Avatar ?? "avatar-default.jpg")" onError="this.src='/upload/avatar/avatar-default.jpg';" style="text-align: center; height: 40px; max-width: 40px; background-color: #ddd !important;">
                        </div>
                        <div class="span11">
                            <div class="row-fluid">
                                <textarea id="txtCommentNote" name="commentnote" class="input-block-level" required="required" rows="3" style="margin: 0px;"></textarea>
                                <a class="btn btn-mini" style="padding: 3px 6px; float: right" id="btn-hideCommentNote"><i class="icon-angle-up"></i></a>
                                <input type="hidden" name="CustomerId" value="@Model.CustomerID"/>
                                <button type="submit" class=" btn btn-mini btn-primary" style="padding: 3px 6px;">Submit</button>
                            </div>
                        </div>
                    </form>
                    <a class="btn btn-mini btn-primary" style="padding: 2px 5px; position: absolute; right: 45px;" id="btn-showCommentNote"><i class="icon-edit"></i> New Note</a>
                </div>
                <div id="lstComment-Note">
                    @foreach (var item in lstNotes)
                    {
                        <div class="row-fluid ticket-comment-row">
                            <div class="span1">
                                <img alt="" src="/Upload/Avatar/@(item.User == null ? "avatar-default.jpg" : item.User.Avatar ?? "avatar-default.jpg")" onError="this.src='/upload/avatar/avatar-default.jpg';" style="text-align: center; height: 40px; max-width: 40px; background-color: #ddd !important;">
                            </div>
                            <div class="span11">
                                <div class="row-fluid">
                                    <strong>@(item.User == null ? "" : item.User.Username)</strong>
                                    <span class="ticket-comment-time">
                                        @item.DateCreated
                                    </span>
                                </div>
                                @if (item.OriginalTicketEmail == null)
                                {
                                    <div class="ticket-comment">
                                        @Html.Raw(!string.IsNullOrEmpty(item.Notes) ? item.Notes.Replace(System.Environment.NewLine, "<br>") : "")
                                    </div>
                                }
                                else
                                {
                                    <div class="ticket-comment">
                                        @Html.Raw(item.OriginalTicketEmail.Body)
                                    </div>
                                    <div class="ticket-comment-attachment">
                                        <ul>
                                            @foreach (var attach in item.OriginalTicketEmail.EmailAttachments)
                                            {
                                                <li><a target="_blank" href="\Ticket\GetFileAttachment?path=@attach.Filename">@attach.Filename.Split('\\').Last()</a></li>
                                            }
                                        </ul>
                                    </div>
                                }
                            </div>
                        </div>
                    }
                </div>

            </div>
        </div>
        <div class="box">
            <div class="box-title">
                <b>Customer Tasks(@lstTasks.Count())</b>
            </div>
            <div class="box-content" style="padding: 0">
                <table id="CustomerTasks" class="table table-hover table-bordered table-fix" data-height='100%'>
                    <thead>
                        <tr>
                            <th>OrderRef</th>
                            <th>Order DatePlaced</th>
                            <th>TaskID</th>
                            <th>Task Type</th>
                            <th>TaskTitle</th>
                            <th>AssignedToUsername</th>
                            <th>AssignedDate</th>
                            <th>CompletedDate</th>
                            <th>TaskDescription</th>
                            <th>Status</th>
                            <th>FinalComments</th>
                            <th>Reason</th>
                            <th>AssignedByUsername</th>
                            <th>RelateToValueID</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in lstTasks)
                        {
                            <tr>
                                <td><a href="/orderview/orderdetail?orderref=@item.OrderRef" target="_blank">@item.OrderRef</a></td>
                                <td>@item.DatePlaced</td>
                                <td>@item.TaskID</td>
                                <td>@item.TaskType</td>
                                <td><a href="javascript:;" onclick="PopupCenter('/orderview/viewtask/@item.TaskID?orderref=@item.OrderRef', 600, 540)" title="View task">@item.TaskTitle</a></td>
                                <td>@item.AssignedToUserName</td>
                                <td>@item.AssignedDate</td>
                                <td>@item.CompletedDate</td>
                                <td>@item.TaskDescription</td>
                                <td>@item.Status</td>
                                <td>@item.FinalComments</td>
                                <td>@item.Reason</td>
                                <td>@item.AssignedByUserName</td>
                                <td>@item.RelateToValueID</td>
                            </tr>
                        }
                    </tbody>
                </table>

            </div>
        </div>
    </div>
</div>

